package Bank;

import java.util.Scanner;

/**
 * @author Ken Veenstra
 * CommandParser.java
 */

public class CommandParser
{
	Scanner inputConsole = new Scanner(System.in);
	String line;
	Bank bank;
	
	public CommandParser(Bank bank)
	{
		this.bank = bank;
		bank.printFile("Menu");
	}
	private String getConsoleLine()
	{
		return inputConsole.nextLine();
	}
	public void readConsole()
	{
		line = getConsoleLine();
		
		mainMenu();
		
		while(inputConsole.hasNext())
		{
			line = getConsoleLine();
			mainMenu();
		}
		inputConsole.close();
	}
	private void mainMenu()
	{
		if(line.equals("1"))
		{
			addMember();
		} 
		else if(line.equals("2"))
		{
			addNormalBankAccount();		
		}
		else if(line.startsWith("3 "))
		{
			
		}
		else if(line.startsWith("8"))
		{
			bank.printBankAccounts();
		}
		else if(line.startsWith("9"))
		{
			printAccountInfo();
		}
		else if(line.equals("h"))
		{
			bank.printFile("Menu");
		}
		else
		{
			System.out.println("No function found for this key, try help [h]");
		} 
	}
	public Scanner getScanner()
	{
		return inputConsole;
	}
	public void addMember()
	{
		String accepted = null;
		String firstName = null;
		String name = null;
		String place = null;
		int age = 0;
		Scanner in = new Scanner(System.in);
		System.out.print("first name?        :"); firstName	= in.nextLine();
		System.out.print("last name?         :"); name 		= in.nextLine();
		System.out.print("where do you live? :"); place 	= in.nextLine();
		System.out.print("age?               :"); age 		= in.nextInt();
		System.out.print("accept              "); accepted  = in.nextLine(); //should get a inputline? getting ERROR from the else below this section
		if(accepted.equals("y"))
		{
			bank.addAccountOwner(name, firstName, place, age, 0, 0);
			System.out.println("==========Added!==========");
		}
		else
		{
			System.out.println("ERROR FAILURE");
			System.out.println("accepted = '" + accepted + "'");
		}
		//TODO press enter to continue?? print menu file again.
	}
	public void printAccountInfo()
	{
		String name = null;
		Scanner in = new Scanner(System.in);
		System.out.print("What is the name of the account owner? :"); name = in.nextLine();
		bank.printMember(name);
	}
	public void addNormalBankAccount()
	{
		int accountID = 0;
		double amount = 0.0;
		Scanner in = new Scanner(System.in);
		System.out.print("what is your account ID?"); accountID = in.nextInt();
		System.out.print("startamount?           :"); amount = in.nextDouble();
		bank.addNormalBankAccount(accountID, amount);
		System.out.println("==========Added!==========");
	}
}
